package part1.oo.ooday04.ooday04test;

public class AnimalTest {
    public static void main(String[] args) {
        //向上造型(多态)的第2点应用
        Master master = new Master();
        Dog dog1 = new Dog("小黑",2,"黑");
        Chick chick1 = new Chick("小白",2,"白");
        Fish fish1 = new Fish("小花",2,"花");
        master.feed(dog1);
        master.feed(chick1);
        master.feed(fish1);


        //向上造型(多态)的第1点应用
        Animal[] animals = new Animal[5];
        animals[0] = new Dog("小黑",2,"黑");
        animals[1] = new Dog("小白",2,"白");
        animals[2] = new Chick("小金",2,"金");
        animals[3] = new Chick("小灰",2,"灰");
        animals[4] = new Fish("小紫",2,"紫");
        for (int i = 0; i < animals.length; i++) {
            System.out.println(animals[i].name);
            animals[i].eat();
            animals[i].drink();
            if (animals[i] instanceof Dog){
                Dog dog = (Dog) (animals[i]);
                dog.lookHome();
            }
            if (animals[i] instanceof Chick){
                Chick chick = (Chick) (animals[i]);
                chick.layEggs();
            }
            if (animals[i] instanceof Swim){
                Swim swim = (Swim) (animals[i]);
                swim.swim();
            }
        }
    }
}
